﻿/*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*
 *~*  17-Oct-2009
 *~*  www.Learning-Leisure.com
 *~*  Project : PB.FBConnect                    Namespace : PB.FBConnect
 *~*  File : FBSession.cs                           Class : FBSession
 *~*  Author : Pinal Bhatt 
 *~*            self@P-Bhatt.com, www.P-Bhatt.com
 *~*   Version History
 *~*            Last Update Date :     Date 17-Oct-2009       Pinal Bhatt
 *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*/

namespace PB.FBConnect
{
    /// <summary>
    /// Facebook Session level settings
    /// </summary>
    public class FBSession
    {
        #region Private Field
        private const string FB_COOKIE_SESSION_KEY = "session_key";
        private const string FB_COOKIE_USER = "user";
        #endregion

        #region Constructor(s)

        public FBSession()
        {
        }

        #endregion

        #region Properties

        /// <summary>
        /// Gets Current Facebook Session Key from the Cookies
        /// </summary>
        public string SessionKey
        {
            get
            {
                return FBHelper.GetFacebookCookie(FB_COOKIE_SESSION_KEY);
            }
        }

        /// <summary>
        /// Gets Facebook user id for currently loged-in user
        /// </summary>
        public long UserID
        {
            get
            {
                long userID = -1;
                long.TryParse(FBHelper.GetFacebookCookie(FB_COOKIE_USER), out userID);
                return userID;
            }
        }
        #endregion

        #region Public Methods

        /// <summary>
        /// Deterrmines whether user is loged-in or not
        /// </summary>
        /// <returns></returns>
        public bool IsConnected()
        {
            return (!string.IsNullOrEmpty(SessionKey) && UserID != -1);
        }

        /// <summary>
        /// Gets currently loged-in facebook user info.
        /// </summary>
        /// <returns></returns>
        public facebook.Schema.user GetCurrentUser()
        {
            return FBHelper.GetFBSchemaUser();
        }

        #endregion
    }
}
